from urllib import request
from urllib import parse
from http.cookiejar import CookieJar

login_url = 'https://www.51moot.net/main/login_validate'
login_data = parse.urlencode({
    'login_name': '13957740075',
    'login_pass': '123456',
    'auto_login': 'option1'
})

header = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36'}

# 创建cookiejar对象
cookiejar = CookieJar()
# 使用cookiejar创建一个handler对象
handler = request.HTTPCookieProcessor(cookiejar)
# 创建opener对象
opener = request.build_opener(handler)

# 登录完成
re = request.Request(login_url, data=login_data.encode('utf-8'))
# cookie保存在opener中
opener.open(re)

p_url = 'https://www.51moot.net/server_hall_2/tea/info'

re1 = request.Request(p_url, headers=header)

resp = opener.open(re1)

print(resp.read().decode())
